Conditions | 1 |
Paths | 32 |
Total Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* global VoxEngine */ |
||
17 | function Framework (options) { |
||
18 | var self = this |
||
19 | options = options || {} |
||
20 | options.behavior = options.behavior || {terminate: true} |
||
21 | var logger = Slf4j.factory(options.logger, 'ama-team.vsf.framework') |
||
22 | var printer = new Printer(options.logger) |
||
23 | |||
24 | /** |
||
25 | * Runs provided scenario. |
||
26 | * |
||
27 | * @param {TScenarioInput} scenario |
||
28 | * |
||
29 | * @return {TRunResult} |
||
30 | */ |
||
31 | this.run = function (scenario) { |
||
32 | return self.execute(self.prepare(scenario)) |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Executes prepared Run |
||
37 | * |
||
38 | * @param {Run} run |
||
39 | * |
||
40 | * @return {TRunResult} |
||
41 | */ |
||
42 | this.execute = function (run) { |
||
43 | printer.scenario(run.getScenario()) |
||
44 | run.initialize() |
||
45 | Binder.bind(run) |
||
46 | return run |
||
47 | .getCompletion() |
||
48 | .then(printer.result, function (reason) { |
||
49 | logger.error('Unexpected error during execution:', reason) |
||
50 | return { |
||
51 | status: OperationStatus.Tripped, |
||
52 | error: reason, |
||
53 | stages: {} |
||
54 | } |
||
55 | }) |
||
56 | .then(function (result) { |
||
57 | if (options.behavior.terminate) { |
||
58 | logger.debug('Shutting down VoxEngine') |
||
59 | VoxEngine.terminate() |
||
60 | } |
||
61 | return result |
||
62 | }) |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Creates run from scenario input. |
||
67 | * |
||
68 | * @param {TScenarioInput} scenario |
||
69 | * |
||
70 | * @return {Run} |
||
71 | */ |
||
72 | this.prepare = function (scenario) { |
||
73 | try { |
||
74 | var barricade = new Barricade({logger: options.logger, printer: printer}) |
||
75 | var normalized = barricade.scenario(scenario) |
||
76 | var settings = { |
||
77 | state: scenario.state || {}, |
||
78 | arguments: scenario.arguments || {}, |
||
79 | container: scenario.container || {}, |
||
80 | logger: options.logger |
||
81 | } |
||
82 | return new Run(normalized, normalized.deserializer, settings) |
||
83 | } catch (e) { |
||
84 | logger.error('Failed to create run, most probably due to invalid scenario') |
||
85 | throw e |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
93 |